﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OnLineExamBLL;
using OnLineExamModel;
using System.Collections.Generic;

namespace OnlineExam.Web.mag
{
    public partial class Web_SingleSelectAdd : System.Web.UI.Page
    {
        SingleSelectedManager bll = new SingleSelectedManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = "增加试题";
            //展示绑定的数据并将它展示在下拉列表中
            if (!IsPostBack)
            {

                string userId = User.Identity.Name;
                var loginuser = new UserManager().GetModel(userId);
                string userName = loginuser.UserName;
                Label i1 = (Label)Page.Master.FindControl("labUser");
                i1.Text = userName;

                string depid = loginuser.DepID + "";

                #region  绑定部门 科目下拉菜单
                this.ddlCourse.DataTextField = "CourseName";
                this.ddlCourse.DataValueField = "CourseID";
                this.ddlCourse.DataSource = new OnLineExamBLL.Course().GetList("depid=" + depid);
                this.ddlCourse.DataBind();
                this.ddlCourse.Items.Insert(0, new ListItem("请选择科目", ""));


                this.ddlDepinfo.DataTextField = "Name";
                this.ddlDepinfo.DataValueField = "ID";
                this.ddlDepinfo.DataSource = new OnLineExamBLL.DepInfo().GetAllList();
                this.ddlDepinfo.DataBind();
                this.ddlDepinfo.Items.Insert(0, new ListItem("请选择", ""));

                this.ddlDepinfo.Items.FindByValue(depid).Selected = true;

                this.ddlDepinfo.Enabled = false;

                if (User.IsInRole("管理员"))
                {
                    this.ddlDepinfo.Enabled = true;
                }
                #endregion

            }
        }
        protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
        {
            SingleProblem sp = new SingleProblem();
            sp.DepID = int.Parse(Session["depid"].ToString());
            sp.CourseID = Convert.ToInt32(ddlCourse.SelectedValue);
            sp.Title = txtTitle.Text;
            sp.AnswerA = txtAnswerA.Text;
            sp.AnswerB = txtAnswerB.Text;
            sp.AnswerC = txtAnswerC.Text;
            sp.AnswerD = txtAnswerD.Text;
            sp.Answer = ddlAnswer.SelectedValue;
            if (SingleSelectedManager.AddSingleSelected(sp))
            {
                lblMessage.Text = "添加成功！";
                txtTitle.Text = string.Empty;
                txtAnswerA.Text = string.Empty;
                txtAnswerB.Text = string.Empty;
                txtAnswerC.Text = string.Empty;
                txtAnswerD.Text = string.Empty;
            }
            else
            {
                lblMessage.Text = "添加失败！";
            }

        }
        protected void imgBtnReturn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("SingleSelectManage.aspx");
        }
    }
}